<#include "../../page.ftl" />
<#assign shmsConstant = statics["cn.hfatec.shms.constants.ShmsConstant"]/>
<#assign security=JspTaglibs["/WEB-INF/security.tld"] />
<div class="tile-body" style="height: 410px;">
    <input type="hidden" id="selectModuleId" name="selectModuleId" value=""/>
    <input type="hidden" id="selectAuthId" name="selectAuthId" value=""/>

    <div class="dd" id="nestable3">
    <#if modulesTable??>
        <#list modulesTable as module>
            <ol class="dd-list">
                <li class="dd-item dd3-item " data-id="1">
                    <div class="dd3-content">${module.moduleName!''}
                        <input type="hidden" name="ids" value="${module.id!''}"/>
                        <input type="hidden" name="moduleId" value="${module.moduleId!''}"/>

                        <div class="controls">
                            <@security.authorize ifAnyGranted="ROLE_AUTH_MODULAR_A">
                                <a onclick="return popAddOrModify('${module.moduleId!''}');" data-toggle="tooltip"
                                   data-placement="top" title="新增" data-original-title="新增">
                                    <i class="fa fa-plus-square-o"></i></a>
                            </@security.authorize>
                            <@security.authorize ifAnyGranted="ROLE_AUTH_MODULAR_E">
                                <a onclick="return popEditOrModify(${module.id!''});" data-toggle="tooltip"
                                   data-placement="top" title="编辑" data-original-title="编辑">
                                    <i class="fa fa-pencil-square-o"></i></a>
                            </@security.authorize>
                            <#if module.parentModuleId != shmsConstant.ROOT_MODULE_ID>
                                <@security.authorize ifAnyGranted="ROLE_AUTH_MODULAR_D">
                                    <a onclick="return deleteModule(${module.id!''},'${module.moduleId!''}');"
                                       data-toggle="tooltip" data-placement="top" title="删除" data-original-title="删除">
                                        <i class="fa fa-times"></i></a>
                                </@security.authorize>
                            </#if>
                        </div>
                    </div>
                    <#if module.childrenModuleList??>
                        <#assign modulesTable=module.childrenModuleList/>
                        <#include "childerModule.ftl"/>
                    </#if>
                </li>
            </ol>
        </#list>
    </#if>
    </div>
</div>
<script>
    $(function () {
        var updateOutput = function (e) {
            var list = e.length ? e : $(e.target);
            output = list.data('output');
            if (window.JSON) {
                $(output).val(window.JSON.stringify(list.nestable('serialize')));//, null, 2));
            } else {
                output.val('JSON browser support required for this demo.');
            }
        };
        $('#nestable3').nestable({
            group: 1
        }).on('change', updateOutput);
        $('.dd3-content .dropdown-menu input').click(function (e) {
            e.preventDefault();
            e.stopPropagation();
        });

        $("#tableContent .tile-body:first").niceScroll();
        $(".dd-list li").click(function (e) {
            if ($(e.target).attr("class") != "dd3-content") {
                return;
            }
            if ($(this).attr("class").indexOf('dd-active') > 0) {
                $(".dd-list li").each(function () {
                    $(this).removeClass("dd-active");
                    $(this).find("li").removeClass("dd-active");
                });
            } else {
                $(".dd-list li").each(function () {
                    $(this).removeClass("dd-active");
                    $(this).find("li").removeClass("dd-active");
                });
                $(this).addClass("dd-active");
            }
            e.preventDefault();
            e.stopPropagation();
            var moduleId = $(this).find("input[name=moduleId]").val();
            $("#selectModuleId").val(moduleId);
            refreshAuth();
        });
    });
</script>

